var baseConfig = require('../baseConfig.js')
function req(url, data, cb, method, isLoading) {
  if (isLoading) {
    wx.showLoading({
      title: '加载中...',
    })
  }
  for (var Key in data) {
    if (data[Key] === null) {
      delete data[Key];
    }
  }
  wx.request({
    url: baseConfig.baseUrl + url,
    data: data,
    method: method || 'GET',
    header: {
      "content-type": "application/x-www-form-urlencoded",
      "UID": wx.getStorageSync("userid")
    },
    complete: function (res) {
      if (isLoading) {
        wx.hideLoading()
      }
    },
    success: function (res) {
      return typeof cb == "function" && cb(res.data)
    },
    fail: function () {
      return typeof cb == "function" && cb(false)
    }
  })
}

function reqLoading(url, data, cb, method) {
  req(url, data, cb, method, true);
}
function reqCloudLoading(url, data, cb, method) {
  reqCloud(url, data, cb, true);
}
module.exports = {
  req: req,
  reqLoading: reqLoading,
}